package com.smallyu.order.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * @Author: small-yu
 * @Package: com.smallyu.order.config
 * @Project: order
 * @Date: 2024/4/18
 * @Time: 1:53
 * 线程池配置
 */
@Configuration
public class YuThreadPoolConfig {

    @Value("${smallyu.thread-pool.pool-size}")
    private Integer poolSize;

    @Value("${smallyu.thread-pool.max-pool-size}")
    private Integer maxPoolSize;

    @Value("${smallyu.thread-pool.keep-alive}")
    private Integer keepAliveTime;

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        return new ThreadPoolExecutor(poolSize,
                maxPoolSize,
                keepAliveTime,
                TimeUnit.MINUTES,
                new LinkedBlockingDeque<>(1000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }
}
